package com.biboheart.adapter.support.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;

public enum ConverterTypeEnum implements BaseEnum<String, String> {
    CONVERTER_STATIC("static", "静态"),
    CONVERTER_REPLACE("replace", "替换"),
    CONVERTER_FILL("fill", "填充"),
    CONVERTER_ENUM("enum", "枚举"),
    CONVERTER_SPLIT("split", "拆解"),
    CONVERTER_RIGHT_RADIX_POINT("rightRadixPoint", "小数点右移"),
    CONVERTER_LEFT_RADIX_POINT("leftRadixPoint", "小数点左移"),
    CONVERTER_TIME_MILLIS("timeToMillis", "时间转时间戳"),
    CONVERTER_MILLIS_TIME("millisToTime", "时间戳转时间"),
    CONVERTER_BINARY_DIGIT("binaryDigit", "二进位"),
    CONVERTER_BINARY_DIGIT_IN("binaryDigitIn", "写入二进位"),
    CONVERTER_BINARY_MILLIS("timeUtils", "取时间"),
    ;
    private final String code;
    private final String desc;

    ConverterTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public static ConverterTypeEnum getConverterType(String code) {
        ConverterTypeEnum[] converterTypes = values();
        for (ConverterTypeEnum converterType : converterTypes) {
            if (converterType.code().equals(code)) {
                return converterType;
            }
        }
        return ConverterTypeEnum.CONVERTER_STATIC;
    }

    public static List<EnumValueObject<String, String>> list() {
        List<EnumValueObject<String, String>> list = new ArrayList<>();
        for (ConverterTypeEnum converterTypeEnum : values()) {
            list.add(new EnumValueObject<>(converterTypeEnum.code(), converterTypeEnum.desc()));
        }
        return list;
    }
}
